<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Content</title>
<jsp:include page="/inc/inc.jsp" />
<script type="text/javascript">
	function initCate(obj) {
		obj.options.length = 1;
		$.post(sys.bp() + '/cnt/cate', function(data) {
			if (data && data.success) {
				var opt = data.obj;
				for ( var i = 0; i < opt.length; i++) {
					var item = new Option(opt[i].name, opt[i].id);
					obj.options.add(item);
				}
			} else {
				alert(data.msg);
			}
		}, 'json');

	}

	function del(id) {
		$.post(sys.bp() + "/cnt/del/" + id, function(data) {
			if (data && data.success) {
				location.reload();
			}
			alert(data.msg);
		}, 'json');
	}

	function checkNaN(n) {
		if (isNaN(n.value)) {
			showMsg("请不要输入数字以外的字符");
			n.value = 30;
			return;
		}
		if (n.value === '') {
			showMsg("请输入一个大于0的整数");
			return;
		}
		gotoPage(1);
	}
	function gotoPage(p) {
		location.href = sys.bp() + "/cnt/show/" + p + "-"
				+ $('#pageSize').val();
	}
</script>
</head>

<body onload="initCate($('#category').get(0))">
	<div class="content">
		<h2 class="title">添加内容</h2>
		<p>&nbsp;</p>
		<div class="entry">
			<form action="<%=request.getContextPath()%>/cnt/add" method="post">
				<table>
					<tr>
						<td width="40px" valign="middle">标题</td>
						<td><input type="text" name="cnt.title"
							style="border: 1px #ccc dashed; width: 300px;"
							onchange="initCate($('#category').get(0));" /></td>
					</tr>
					<tr>
						<td width="40px" valign="middle">类别</td>
						<td><select name="cnt.cid" id="category"
							style="border: 1px #ccc dashed;"><option value="0">默认分类</option></select></td>
					</tr>
					<tr>
						<td valign="middle">内容</td>
						<td><textarea name="cnt.note"
								style="border: 1px #ccc dashed; width: 300px; height: 50px; resize: none;"></textarea></td>
					</tr>
					<tr>
						<td colspan="2" align="center"><input type="submit"
							value="添加内容" class="button" /></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<hr size="1" noshade="noshade"/>
	<c:if test="${not empty cntlist }">
		<c:forEach items="${cntlist}" var="cnt">
			<div class="content">
				<h2 class="title">
					<span>${cnt.title }</span>
				</h2>
				<p class="byline">
					<small>Category is [${cnt.category}]</small>
				</p>
				<div class="entry">
					<p>${cnt.note }</p>
				</div>
				<div class="meta">
					<a href="javascript:del('${cnt.id }')">删除</a>
				</div>
			</div>
		</c:forEach>
	</c:if>
	&nbsp; 每页显示：
	<input type="text" id="pageSize" name="pageSize"
		style="border: none; border-bottom: 1px #ccc solid; width: 20px;"
		value="${pager.pageSize }" onchange="checkNaN(this)" maxlength="2" />条记录
	| 总记录：${pager.totalRows } | 当前页 / 总页数
	:${pager.currentPage}/${pager.totalPages } &nbsp;
	<c:if test="${pager.previous}">
		<a href="javascript:gotoPage(${pager.currentPage - 1 })"> 上一页</a>
	</c:if>
	<c:if test="${pager.next}">
		<a href="javascript:gotoPage(${pager.currentPage + 1 })"> 下一页</a>
	</c:if>
	<c:if test="${pager.totalRows == 0 }">
         没有记录
    </c:if>
</body>
</html>
